home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / emacs-complete / fsf / emacs / lisp / iso-cvt.el < prev    next >
Lisp/Scheme  |  1994-08-13  |  17KB  |  701 lines

  1. ;; iso-cvt.el -- translate to ISO 8859-1 from/to net/TeX conventions
  2. ;; Copyright © 1993, 1994 Free Software Foundation, Inc.
  3. ;; Was formerly called gm-lingo.el.
  4.  
  5. ;; Author: Michael Gschwind <mike@vlsivie.tuwien.ac.at>
  6. ;; Keywords: tex, iso, latin, i18n
  7.  
  8. ;; This file is part of GNU Emacs.
  9.  
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ;; GNU General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  22. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. ;;; Commentary: 
  25. ;; This lisp code server two purposes, both of which involve 
  26. ;; the translation of various conventions for representing European 
  27. ;; character sets to ISO 8859-1.
  28.  
  29. ; Net support: 
  30. ; Various conventions exist in Newsgroups on how to represent national 
  31. ; characters. The functions provided here translate these net conventions 
  32. ; to ISO.
  33. ;
  34. ; Calling `iso-german' will turn the net convention for umlauts ("a etc.) 
  35. ; into ISO latin1 umlaute for easy reading.
  36. ; 'iso-spanish' will turn net conventions for representing spanish 
  37. ; to ISO latin1. (Note that accents are omitted in news posts most 
  38. ; of the time, only enye is escaped.)
  39.  
  40. ; TeX support
  41. ; This mode installs hooks which change TeX files to ISO Latin-1 for 
  42. ; simplified editing. When the TeX file is saved, ISO latin1 characters are
  43. ; translated back to escape sequences.
  44. ;
  45. ; An alternative is a TeX style that handles 8 bit ISO files 
  46. ; (available on ftp.vlsivie.tuwien.ac.at in /pub/8bit)  
  47. ; - but these files are difficult to transmit ... so while the net is  
  48. ; still @ 7 bit this may be useful
  49.  
  50. ;; TO DO:
  51. ; The net support should install hooks (like TeX support does) 
  52. ; which recognizes certains news groups and translates all articles from 
  53. ; those groups. 
  54. ;
  55. ; Cover more cases for translation (There is an infinite number of ways to 
  56. ; represent accented characters in TeX)
  57.  
  58. ;; SEE ALSO:
  59. ; If you are interested in questions related to using the ISO 8859-1 
  60. ; characters set (configuring emacs, Unix, etc. to use ISO), then you
  61. ; can get the ISO 8859-1 FAQ via anonymous ftp from 
  62. ; ftp.vlsivie.tuwien.ac.at in /pub/bit/FAQ-ISO-8859-1
  63.  
  64. ;;; Code:
  65.  
  66. (provide 'iso-cvt)
  67.  
  68. (defvar iso-spanish-trans-tab
  69.   '(
  70.     ("~n" "ñ")
  71.     ("\([a-zA-Z]\)#" "\\1ñ")
  72.     ("~N" "Ñ")
  73.     ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
  74.     ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
  75.     ("\\([-a-zA-Z]\\)'o" "\\1ó")
  76.     ("\\([-a-zA-Z]\\)'O" "\\Ó")
  77.     ("\\([-a-zA-Z]\\)'e" "\\1é")
  78.     ("\\([-a-zA-Z]\\)'E" "\\1É")
  79.     ("\\([-a-zA-Z]\\)'a" "\\1á")
  80.     ("\\([-a-zA-Z]\\)'A" "\\1A")
  81.     ("\\([-a-zA-Z]\\)'i" "\\1í")
  82.     ("\\([-a-zA-Z]\\)'I" "\\1Í")
  83.     )
  84.   "Spanish translation table.")
  85.  
  86. (defun iso-translate-conventions (trans-tab)
  87.   "Use the translation table TRANS-TAB to translate the current buffer."
  88.   (save-excursion
  89.     (goto-char (point-min))
  90.     (let ((work-tab trans-tab)
  91.       (buffer-read-only nil)
  92.       (case-fold-search nil))
  93.       (while work-tab
  94.     (save-excursion
  95.       (let ((trans-this (car work-tab)))
  96.         (while (re-search-forward (car trans-this) nil t)
  97.           (replace-match (car (cdr trans-this)) t nil)))
  98.       (setq work-tab (cdr work-tab)))))))
  99.  
  100. (defun iso-spanish ()
  101.   "Translate net conventions for Spanish to ISO 8859-1."
  102.   (interactive)
  103.   (iso-translate-conventions iso-spanish-trans-tab))
  104.  
  105. (defvar iso-aggressive-german-trans-tab
  106.   '(
  107.     ("\"a" "ä")
  108.     ("\"A" "Ä")
  109.     ("\"o" "ö")
  110.     ("\"O" "Ö")
  111.     ("\"u" "ü")
  112.     ("\"U" "Ü")
  113.     ("\"s" "ß")
  114.     ("\\\\3" "ß")
  115.     )
  116.   "German translation table. 
  117. This table uses an aggressive translation approach and may translate 
  118. erroneously translate too much.")
  119.  
  120. (defvar iso-conservative-german-trans-tab
  121.   '(
  122.     ("\\([-a-zA-Z\"`]\\)\"a" "\\1ä")
  123.     ("\\([-a-zA-Z\"`]\\)\"A" "\\1Ä")
  124.     ("\\([-a-zA-Z\"`]\\)\"o" "\\1ö")
  125.     ("\\([-a-zA-Z\"`]\\)\"O" "\\1Ö")
  126.     ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
  127.     ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
  128.     ("\\([-a-zA-Z\"`]\\)\"s" "\\1ß")
  129.     ("\\([-a-zA-Z\"`]\\)\\\\3" "\\1ß")
  130.     )
  131.   "German translation table.
  132. This table uses a conservative translation approach and may translate too 
  133. little.")
  134.  
  135.  
  136. (defvar iso-german-trans-tab iso-aggressive-german-trans-tab 
  137.   "Currently active translation table for German.")
  138.  
  139. (defun iso-german ()
  140.  "Translate net conventions for German to ISO 8859-1."
  141.  (interactive)
  142.  (iso-translate-conventions iso-german-trans-tab))
  143.  
  144. (defvar iso-iso2tex-trans-tab
  145.   '(
  146.     ("ä" "{\\\\\"a}")
  147.     ("à" "{\\\\`a}")
  148.     ("á" "{\\\\'a}")
  149.     ("ã" "{\\\\~a}")
  150.     ("â" "{\\\\^a}")
  151.     ("ë" "{\\\\\"e}")
  152.     ("è" "{\\\\`e}")
  153.     ("é" "{\\\\'e}")
  154.     ("ê" "{\\\\^e}")
  155.     ("ï" "{\\\\\"\\\\i}")
  156.     ("ì" "{\\\\`\\\\i}")
  157.     ("í" "{\\\\'\\\\i}")
  158.     ("î" "{\\\\^\\\\i}")
  159.     ("ö" "{\\\\\"o}")
  160.     ("ò" "{\\\\`o}")
  161.     ("ó" "{\\\\'o}")
  162.     ("õ" "{\\\\~o}")
  163.     ("ô" "{\\\\^o}")
  164.     ("ü" "{\\\\\"u}")
  165.     ("ù" "{\\\\`u}")
  166.     ("ú" "{\\\\'u}")
  167.     ("û" "{\\\\^u}")
  168.     ("Ä" "{\\\\\"A}")
  169.     ("À" "{\\\\`A}")
  170.     ("Á" "{\\\\'A}")
  171.     ("Ã" "{\\\\~A}")
  172.     ("Â" "{\\\\^A}")
  173.     ("Ë" "{\\\\\"E}")
  174.     ("È" "{\\\\`E}")
  175.     ("É" "{\\\\'E}")
  176.     ("Ê" "{\\\\^E}")
  177.     ("Ï" "{\\\\\"I}")
  178.     ("Ì" "{\\\\`I}")
  179.     ("Í" "{\\\\'I}")
  180.     ("Î" "{\\\\^I}")
  181.     ("Ö" "{\\\\\"O}")
  182.     ("Ò" "{\\\\`O}")
  183.     ("Ó" "{\\\\'O}")
  184.     ("Õ" "{\\\\~O}")
  185.     ("Ô" "{\\\\^O}")
  186.     ("Ü" "{\\\\\"U}")
  187.     ("Ù" "{\\\\`U}")
  188.     ("Ú" "{\\\\'U}")
  189.     ("Û" "{\\\\^U}")
  190.     ("ñ" "{\\\\~n}")
  191.     ("Ñ" "{\\\\~N}")
  192.     ("ç" "{\\\\c c}")
  193.     ("Ç" "{\\\\c C}")
  194.     ("ß" "{\\\\ss}")
  195.     ("\306" "{\\\\AE}")
  196.     ("\346" "{\\\\ae}")
  197.     ("\305" "{\\\\o A}")
  198.     ("\345" "{\\\\o a}")
  199.     ("\251" "{\\\\copyright}")
  200.     ("¿" "{?`}")
  201.     ("¡" "{!`}")
  202.     )
  203.   "Translation table for translating ISO 8859-1 characters to TeX sequences.")
  204.  
  205.  
  206.  
  207.  
  208. (defun iso-iso2tex ()
  209.  "Translate ISO 8859-1 characters to TeX sequences."
  210.  (interactive)
  211.  (iso-translate-conventions iso-iso2tex-trans-tab))
  212.  
  213.  
  214. (defvar iso-tex2iso-trans-tab
  215.   '(
  216.     ("{\\\\\"a}" "ä")
  217.     ("{\\\\`a}" "à")
  218.     ("{\\\\'a}" "á")
  219.     ("{\\\\~a}" "ã")
  220.     ("{\\\\^a}" "â")
  221.     ("{\\\\\"e}" "ë")
  222.     ("{\\\\`e}" "è")
  223.     ("{\\\\'e}" "é")
  224.     ("{\\\\^e}" "ê")
  225.     ("{\\\\\"\\\\i}" "ï")
  226.     ("{\\\\`\\\\i}" "ì")
  227.     ("{\\\\'\\\\i}" "í")
  228.     ("{\\\\^\\\\i}" "î")
  229.     ("{\\\\\"i}" "ï")
  230.     ("{\\\\`i}" "ì")
  231.     ("{\\\\'i}" "í")
  232.     ("{\\\\^i}" "î")
  233.     ("{\\\\\"o}" "ö")
  234.     ("{\\\\`o}" "ò")
  235.     ("{\\\\'o}" "ó")
  236.     ("{\\\\~o}" "õ")
  237.     ("{\\\\^o}" "ô")
  238.     ("{\\\\\"u}" "ü")
  239.     ("{\\\\`u}" "ù")
  240.     ("{\\\\'u}" "ú")
  241.     ("{\\\\^u}" "û")
  242.     ("{\\\\\"A}" "Ä")
  243.     ("{\\\\`A}" "À")
  244.     ("{\\\\'A}" "Á")
  245.     ("{\\\\~A}" "Ã")
  246.     ("{\\\\^A}" "Â")
  247.     ("{\\\\\"E}" "Ë")
  248.     ("{\\\\`E}" "È")
  249.     ("{\\\\'E}" "É")
  250.     ("{\\\\^E}" "Ê")
  251.     ("{\\\\\"I}" "Ï")
  252.     ("{\\\\`I}" "Ì")
  253.     ("{\\\\'I}" "Í")
  254.     ("{\\\\^I}" "Î")
  255.     ("{\\\\\"O}" "Ö")
  256.     ("{\\\\`O}" "Ò")
  257.     ("{\\\\'O}" "Ó")
  258.     ("{\\\\~O}" "Õ")
  259.     ("{\\\\^O}" "Ô")
  260.     ("{\\\\\"U}" "Ü")
  261.     ("{\\\\`U}" "Ù")
  262.     ("{\\\\'U}" "Ú")
  263.     ("{\\\\^U}" "Û")
  264.     ("{\\\\~n}" "ñ")
  265.     ("{\\\\~N}" "Ñ")
  266.     ("{\\\\c c}" "ç")
  267.     ("{\\\\c C}" "Ç")
  268.     ("\\\\\"a" "ä")
  269.     ("\\\\`a" "à")
  270.     ("\\\\'a" "á")
  271.     ("\\\\~a" "ã")
  272.     ("\\\\^a" "â")
  273.     ("\\\\\"e" "ë")
  274.     ("\\\\`e" "è")
  275.     ("\\\\'e" "é")
  276.     ("\\\\^e" "ê")
  277.     ("\\\\\"\\\\i" "ï")
  278.     ("\\\\`\\\\i" "ì")
  279.     ("\\\\'\\\\i" "í")
  280.     ("\\\\^\\\\i" "î")
  281.     ("\\\\\"i" "ï")
  282.     ("\\\\`i" "ì")
  283.     ("\\\\'i" "í")
  284.     ("\\\\^i" "î")
  285.     ("\\\\\"o" "ö")
  286.     ("\\\\`o" "ò")
  287.     ("\\\\'o" "ó")
  288.     ("\\\\~o" "õ")
  289.     ("\\\\^o" "ô")
  290.     ("\\\\\"u" "ü")
  291.     ("\\\\`u" "ù")
  292.     ("\\\\'u" "ú")
  293.     ("\\\\^u" "û")
  294.     ("\\\\\"A" "Ä")
  295.     ("\\\\`A" "À")
  296.     ("\\\\'A" "Á")
  297.     ("\\\\~A" "Ã")
  298.     ("\\\\^A" "Â")
  299.     ("\\\\\"E" "Ë")
  300.     ("\\\\`E" "È")
  301.     ("\\\\'E" "É")
  302.     ("\\\\^E" "Ê")
  303.     ("\\\\\"I" "Ï")
  304.     ("\\\\`I" "Ì")
  305.     ("\\\\'I" "Í")
  306.     ("\\\\^I" "Î")
  307.     ("\\\\\"O" "Ö")
  308.     ("\\\\`O" "Ò")
  309.     ("\\\\'O" "Ó")
  310.     ("\\\\~O" "Õ")
  311.     ("\\\\^O" "Ô")
  312.     ("\\\\\"U" "Ü")
  313.     ("\\\\`U" "Ù")
  314.     ("\\\\'U" "Ú")
  315.     ("\\\\^U" "Û")
  316.     ("\\\\~n" "ñ")
  317.     ("\\\\~N" "Ñ")
  318.     ("\\\\\"{a}" "ä")
  319.     ("\\\\`{a}" "à")
  320.     ("\\\\'{a}" "á")
  321.     ("\\\\~{a}" "ã")
  322.     ("\\\\^{a}" "â")
  323.     ("\\\\\"{e}" "ë")
  324.     ("\\\\`{e}" "è")
  325.     ("\\\\'{e}" "é")
  326.     ("\\\\^{e}" "ê")
  327.     ("\\\\\"{\\\\i}" "ï")
  328.     ("\\\\`{\\\\i}" "ì")
  329.     ("\\\\'{\\\\i}" "í")
  330.     ("\\\\^{\\\\i}" "î")
  331.     ("\\\\\"{i}" "ï")
  332.     ("\\\\`{i}" "ì")
  333.     ("\\\\'{i}" "í")
  334.     ("\\\\^{i}" "î")
  335.     ("\\\\\"{o}" "ö")
  336.     ("\\\\`{o}" "ò")
  337.     ("\\\\'{o}" "ó")
  338.     ("\\\\~{o}" "õ")
  339.     ("\\\\^{o}" "ô")
  340.     ("\\\\\"{u}" "ü")
  341.     ("\\\\`{u}" "ù")
  342.     ("\\\\'{u}" "ú")
  343.     ("\\\\^{u}" "û")
  344.     ("\\\\\"{A}" "Ä")
  345.     ("\\\\`{A}" "À")
  346.     ("\\\\'{A}" "Á")
  347.     ("\\\\~{A}" "Ã")
  348.     ("\\\\^{A}" "Â")
  349.     ("\\\\\"{E}" "Ë")
  350.     ("\\\\`{E}" "È")
  351.     ("\\\\'{E}" "É")
  352.     ("\\\\^{E}" "Ê")
  353.     ("\\\\\"{I}" "Ï")
  354.     ("\\\\`{I}" "Ì")
  355.     ("\\\\'{I}" "Í")
  356.     ("\\\\^{I}" "Î")
  357.     ("\\\\\"{O}" "Ö")
  358.     ("\\\\`{O}" "Ò")
  359.     ("\\\\'{O}" "Ó")
  360.     ("\\\\~{O}" "Õ")
  361.     ("\\\\^{O}" "Ô")
  362.     ("\\\\\"{U}" "Ü")
  363.     ("\\\\`{U}" "Ù")
  364.     ("\\\\'{U}" "Ú")
  365.     ("\\\\^{U}" "Û")
  366.     ("\\\\~{n}" "ñ")
  367.     ("\\\\~{N}" "Ñ")
  368.     ("\\\\c{c}" "ç")
  369.     ("\\\\c{C}" "Ç")
  370.     ("{\\\\ss}" "ß")
  371.     ("{\\\\AE}" "\306")
  372.     ("{\\\\ae}" "\346")
  373.     ("{\\\\o A}" "\305")
  374.     ("\\\\o{A}" "\305")
  375.     ("{\\\\o a}" "\345")
  376.     ("\\\\o{a}" "\345")
  377.     ("{\\\\copyright}" "\251")
  378.     ("\\\\copyright{}" "\251")
  379.     ("{\\?`}" "¿")
  380.     ("{!`}" "¡")
  381.     ("\\?`" "¿")
  382.     ("!`" "¡")
  383.     )
  384.   "Translation table for translating TeX sequences to ISO 8859-1 characters. 
  385. This table is not exhaustive (and due to TeX's power can never be). It only
  386. contains commonly used sequences.")
  387.  
  388. (defun iso-tex2iso ()
  389.  "Translate TeX sequences to ISO 8859-1 characters."
  390.  (interactive)
  391.  (iso-translate-conventions iso-tex2iso-trans-tab))
  392.  
  393. (defvar iso-gtex2iso-trans-tab
  394.   '(
  395.     ("{\\\\\"a}" "ä")
  396.     ("{\\\\`a}" "à")
  397.     ("{\\\\'a}" "á")
  398.     ("{\\\\~a}" "ã")
  399.     ("{\\\\^a}" "â")
  400.     ("{\\\\\"e}" "ë")
  401.     ("{\\\\`e}" "è")
  402.     ("{\\\\'e}" "é")
  403.     ("{\\\\^e}" "ê")
  404.     ("{\\\\\"\\\\i}" "ï")
  405.     ("{\\\\`\\\\i}" "ì")
  406.     ("{\\\\'\\\\i}" "í")
  407.     ("{\\\\^\\\\i}" "î")
  408.     ("{\\\\\"i}" "ï")
  409.     ("{\\\\`i}" "ì")
  410.     ("{\\\\'i}" "í")
  411.     ("{\\\\^i}" "î")
  412.     ("{\\\\\"o}" "ö")
  413.     ("{\\\\`o}" "ò")
  414.     ("{\\\\'o}" "ó")
  415.     ("{\\\\~o}" "õ")
  416.     ("{\\\\^o}" "ô")
  417.     ("{\\\\\"u}" "ü")
  418.     ("{\\\\`u}" "ù")
  419.     ("{\\\\'u}" "ú")
  420.     ("{\\\\^u}" "û")
  421.     ("{\\\\\"A}" "Ä")
  422.     ("{\\\\`A}" "À")
  423.     ("{\\\\'A}" "Á")
  424.     ("{\\\\~A}" "Ã")
  425.     ("{\\\\^A}" "Â")
  426.     ("{\\\\\"E}" "Ë")
  427.     ("{\\\\`E}" "È")
  428.     ("{\\\\'E}" "É")
  429.     ("{\\\\^E}" "Ê")
  430.     ("{\\\\\"I}" "Ï")
  431.     ("{\\\\`I}" "Ì")
  432.     ("{\\\\'I}" "Í")
  433.     ("{\\\\^I}" "Î")
  434.     ("{\\\\\"O}" "Ö")
  435.     ("{\\\\`O}" "Ò")
  436.     ("{\\\\'O}" "Ó")
  437.     ("{\\\\~O}" "Õ")
  438.     ("{\\\\^O}" "Ô")
  439.     ("{\\\\\"U}" "Ü")
  440.     ("{\\\\`U}" "Ù")
  441.     ("{\\\\'U}" "Ú")
  442.     ("{\\\\^U}" "Û")
  443.     ("{\\\\~n}" "ñ")
  444.     ("{\\\\~N}" "Ñ")
  445.     ("{\\\\c c}" "ç")
  446.     ("{\\\\c C}" "Ç")
  447.     ("\\\\\"a" "ä")
  448.     ("\\\\`a" "à")
  449.     ("\\\\'a" "á")
  450.     ("\\\\~a" "ã")
  451.     ("\\\\^a" "â")
  452.     ("\\\\\"e" "ë")
  453.     ("\\\\`e" "è")
  454.     ("\\\\'e" "é")
  455.     ("\\\\^e" "ê")
  456.     ("\\\\\"\\\\i" "ï")
  457.     ("\\\\`\\\\i" "ì")
  458.     ("\\\\'\\\\i" "í")
  459.     ("\\\\^\\\\i" "î")
  460.     ("\\\\\"i" "ï")
  461.     ("\\\\`i" "ì")
  462.     ("\\\\'i" "í")
  463.     ("\\\\^i" "î")
  464.     ("\\\\\"o" "ö")
  465.     ("\\\\`o" "ò")
  466.     ("\\\\'o" "ó")
  467.     ("\\\\~o" "õ")
  468.     ("\\\\^o" "ô")
  469.     ("\\\\\"u" "ü")
  470.     ("\\\\`u" "ù")
  471.     ("\\\\'u" "ú")
  472.     ("\\\\^u" "û")
  473.     ("\\\\\"A" "Ä")
  474.     ("\\\\`A" "À")
  475.     ("\\\\'A" "Á")
  476.     ("\\\\~A" "Ã")
  477.     ("\\\\^A" "Â")
  478.     ("\\\\\"E" "Ë")
  479.     ("\\\\`E" "È")
  480.     ("\\\\'E" "É")
  481.     ("\\\\^E" "Ê")
  482.     ("\\\\\"I" "Ï")
  483.     ("\\\\`I" "Ì")
  484.     ("\\\\'I" "Í")
  485.     ("\\\\^I" "Î")
  486.     ("\\\\\"O" "Ö")
  487.     ("\\\\`O" "Ò")
  488.     ("\\\\'O" "Ó")
  489.     ("\\\\~O" "Õ")
  490.     ("\\\\^O" "Ô")
  491.     ("\\\\\"U" "Ü")
  492.     ("\\\\`U" "Ù")
  493.     ("\\\\'U" "Ú")
  494.     ("\\\\^U" "Û")
  495.     ("\\\\~n" "ñ")
  496.     ("\\\\~N" "Ñ")
  497.     ("\\\\\"{a}" "ä")
  498.     ("\\\\`{a}" "à")
  499.     ("\\\\'{a}" "á")
  500.     ("\\\\~{a}" "ã")
  501.     ("\\\\^{a}" "â")
  502.     ("\\\\\"{e}" "ë")
  503.     ("\\\\`{e}" "è")
  504.     ("\\\\'{e}" "é")
  505.     ("\\\\^{e}" "ê")
  506.     ("\\\\\"{\\\\i}" "ï")
  507.     ("\\\\`{\\\\i}" "ì")
  508.     ("\\\\'{\\\\i}" "í")
  509.     ("\\\\^{\\\\i}" "î")
  510.     ("\\\\\"{i}" "ï")
  511.     ("\\\\`{i}" "ì")
  512.     ("\\\\'{i}" "í")
  513.     ("\\\\^{i}" "î")
  514.     ("\\\\\"{o}" "ö")
  515.     ("\\\\`{o}" "ò")
  516.     ("\\\\'{o}" "ó")
  517.     ("\\\\~{o}" "õ")
  518.     ("\\\\^{o}" "ô")
  519.     ("\\\\\"{u}" "ü")
  520.     ("\\\\`{u}" "ù")
  521.     ("\\\\'{u}" "ú")
  522.     ("\\\\^{u}" "û")
  523.     ("\\\\\"{A}" "Ä")
  524.     ("\\\\`{A}" "À")
  525.     ("\\\\'{A}" "Á")
  526.     ("\\\\~{A}" "Ã")
  527.     ("\\\\^{A}" "Â")
  528.     ("\\\\\"{E}" "Ë")
  529.     ("\\\\`{E}" "È")
  530.     ("\\\\'{E}" "É")
  531.     ("\\\\^{E}" "Ê")
  532.     ("\\\\\"{I}" "Ï")
  533.     ("\\\\`{I}" "Ì")
  534.     ("\\\\'{I}" "Í")
  535.     ("\\\\^{I}" "Î")
  536.     ("\\\\\"{O}" "Ö")
  537.     ("\\\\`{O}" "Ò")
  538.     ("\\\\'{O}" "Ó")
  539.     ("\\\\~{O}" "Õ")
  540.     ("\\\\^{O}" "Ô")
  541.     ("\\\\\"{U}" "Ü")
  542.     ("\\\\`{U}" "Ù")
  543.     ("\\\\'{U}" "Ú")
  544.     ("\\\\^{U}" "Û")
  545.     ("\\\\~{n}" "ñ")
  546.     ("\\\\~{N}" "Ñ")
  547.     ("\\\\c{c}" "ç")
  548.     ("\\\\c{C}" "Ç")
  549.     ("{\\\\ss}" "ß")
  550.     ("{\\\\AE}" "\306")
  551.     ("{\\\\ae}" "\346")
  552.     ("{\\\\o A}" "\305")
  553.     ("\\\\o{A}" "\305")
  554.     ("{\\\\o a}" "\345")
  555.     ("\\\\o{a}" "\345")
  556.     ("{\\\\copyright}" "\251")
  557.     ("\\\\copyright{}" "\251")
  558.     ("?`" "¿")
  559.     ("!`" "¡")
  560.     ("{?`}" "¿")
  561.     ("{!`}" "¡")
  562.     ("\"a" "ä")
  563.     ("\"A" "Ä")
  564.     ("\"o" "ö")
  565.     ("\"O" "Ö")
  566.     ("\"u" "ü")
  567.     ("\"U" "Ü")
  568.     ("\"s" "ß")
  569.     ("\\\\3" "ß")
  570.     )
  571.   "Translation table for translating German TeX sequences to ISO 8859-1.
  572. This table is not exhaustive (and due to TeX's power can never be).  It only
  573. contains commonly used sequences.")
  574.  
  575. (defvar iso-iso2gtex-trans-tab
  576.   '(
  577.     ("ä" "\"a")
  578.     ("à" "{\\\\`a}")
  579.     ("á" "{\\\\'a}")
  580.     ("ã" "{\\\\~a}")
  581.     ("â" "{\\\\^a}")
  582.     ("ë" "{\\\\\"e}")
  583.     ("è" "{\\\\`e}")
  584.     ("é" "{\\\\'e}")
  585.     ("ê" "{\\\\^e}")
  586.     ("ï" "{\\\\\"\\\\i}")
  587.     ("ì" "{\\\\`\\\\i}")
  588.     ("í" "{\\\\'\\\\i}")
  589.     ("î" "{\\\\^\\\\i}")
  590.     ("ö" "\"o")
  591.     ("ò" "{\\\\`o}")
  592.     ("ó" "{\\\\'o}")
  593.     ("õ" "{\\\\~o}")
  594.     ("ô" "{\\\\^o}")
  595.     ("ü" "\"u")
  596.     ("ù" "{\\\\`u}")
  597.     ("ú" "{\\\\'u}")
  598.     ("û" "{\\\\^u}")
  599.     ("Ä" "\"A")
  600.     ("À" "{\\\\`A}")
  601.     ("Á" "{\\\\'A}")
  602.     ("Ã" "{\\\\~A}")
  603.     ("Â" "{\\\\^A}")
  604.     ("Ë" "{\\\\\"E}")
  605.     ("È" "{\\\\`E}")
  606.     ("É" "{\\\\'E}")
  607.     ("Ê" "{\\\\^E}")
  608.     ("Ï" "{\\\\\"I}")
  609.     ("Ì" "{\\\\`I}")
  610.     ("Í" "{\\\\'I}")
  611.     ("Î" "{\\\\^I}")
  612.     ("Ö" "\"O")
  613.     ("Ò" "{\\\\`O}")
  614.     ("Ó" "{\\\\'O}")
  615.     ("Õ" "{\\\\~O}")
  616.     ("Ô" "{\\\\^O}")
  617.     ("Ü" "\"U")
  618.     ("Ù" "{\\\\`U}")
  619.     ("Ú" "{\\\\'U}")
  620.     ("Û" "{\\\\^U}")
  621.     ("ñ" "{\\\\~n}")
  622.     ("Ñ" "{\\\\~N}")
  623.     ("ç" "{\\\\c c}")
  624.     ("Ç" "{\\\\c C}")
  625.     ("ß" "\"s")
  626.     ("\306" "{\\\\AE}")
  627.     ("\346" "{\\\\ae}")
  628.     ("\305" "{\\\\o A}")
  629.     ("\345" "{\\\\o a}")
  630.     ("\251" "{\\\\copyright}")
  631.     ("¿" "{?`}")
  632.     ("¡" "{!`}")
  633.     )
  634.   "Translation table for translating ISO 8859-1 characters to German TeX.")
  635.  
  636. (defun iso-gtex2iso ()
  637.  "Translate German TeX sequences to ISO 8859-1 characters."
  638.  (interactive)
  639.  (iso-translate-conventions iso-gtex2iso-trans-tab))
  640.  
  641.  
  642. (defun iso-iso2gtex ()
  643.  "Translate ISO 8859-1 characters to German TeX sequences."
  644.  (interactive)
  645.  (iso-translate-conventions iso-iso2gtex-trans-tab))
  646.  
  647.  
  648. (defun iso-german-tex-p ()
  649.  "Check if tex buffer is German LaTeX."
  650.  (save-excursion
  651.    (save-restriction
  652.      (widen)
  653.      (goto-char (point-min))
  654.      (re-search-forward "\\\\documentstyle\\[.*german.*\\]" nil t))))
  655.  
  656. (defun iso-fix-iso2tex ()
  657.   "Turn ISO 8859-1 (aka. ISO Latin-1) buffer into TeX sequences.
  658. If German TeX is used, German TeX sequences are generated."
  659.   (if (or (equal major-mode 'latex-mode)
  660.       (equal major-mode 'LaTeX-mode)) ; AucTeX wants this
  661.       (if (iso-german-tex-p)
  662.       (iso-iso2gtex)
  663.     (iso-iso2tex)))
  664.   (if (or (equal major-mode 'tex-mode)
  665.       (equal major-mode 'TeX-mode) ; AucTeX wants this
  666.       (equal major-mode 'plain-tex-mode))
  667.       (iso-iso2tex)))
  668.  
  669. (defun iso-fix-tex2iso ()
  670.   "Turn TeX sequences into ISO 8859-1 (aka. ISO Latin-1) characters.
  671. This function recognices German TeX buffers."
  672.   (if (or (equal major-mode 'latex-mode)
  673.       (equal major-mode 'Latex-mode)) ; AucTeX wants this
  674.       (if (iso-german-tex-p)
  675.       (iso-gtex2iso)
  676.     (iso-tex2iso)))
  677.   (if (or (equal major-mode 'tex-mode)
  678.       (equal major-mode 'TeX-mode)  ; AucTeX wants this
  679.       (equal major-mode 'plain-tex-mode))
  680.       (iso-tex2iso)))
  681.  
  682. (defun iso-cvt-ffh ()
  683.   "find-file-hook for iso-cvt-cvt.el."
  684.   (iso-fix-tex2iso)
  685.   (set-buffer-modified-p nil))
  686.  
  687. (defun iso-cvt-wfh ()
  688.   "write file hook for iso-cvt-cvt.el."
  689.   (iso-fix-iso2tex))
  690.  
  691. (defun iso-cvt-ash ()
  692.   "after save hook for iso-cvt-cvt.el."
  693.   (iso-fix-tex2iso)
  694.   (set-buffer-modified-p nil))
  695.  
  696. (add-hook 'find-file-hooks 'iso-cvt-ffh)
  697. (add-hook 'write-file-hooks 'iso-cvt-wfh)
  698. (add-hook 'after-save-hook 'iso-cvt-ash)
  699.  
  700. ;;; iso-cvt.el ends here
  701.